<template>
	<div class="components-container">
    <div class="header-form">
        <div class="layui-inline">
          <label class="layui-form-label">所属区域</label>
          <div class="layui-input-inline">
            <el-select v-model="selectData.AssasaidEqual" placeholder="请选择区域">
                <el-option label="全部" :value="null"></el-option>
                <el-option v-for="item in areaTypes"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"
                        >
                </el-option>
            </el-select>
              </div>
        </div>
        <div class="layui-inline">
            <label  class="layui-form-label">位置编号</label>
             <div class="layui-input-inline">
                <el-input  v-model="selectData.AssnoLike" placeholder="请输入位置编号"></el-input>
             </div>
        </div>
          <el-button type="primary"  @click="btnSearch" :loading="this.$store.state.isloading">搜索</el-button>
          <el-button  @click="btnRepeat" >重置</el-button>
        </div>
        <div>
            <ul class="toolList">
                <li v-if="btnShow(item.BTNVALUE)" v-for="(item, index) in $store.state.btnListCommon" @click="operate(item.BTNVALUE)">
                    <el-button type="primary" :value="item.BTNSHOWNAME" v-text="item.BTNSHOWNAME"></el-button>
                </li>
            </ul>
        </div>
        <dataTable :headList="headList" :dataList="dataList" :pageOrder="pageOrder" @pageChange="pageChange" @selectRow="selectRow"></dataTable>
        
        <ashesManageMain ref="sweetModalMain" :orderType="order" @refreshData="getData"></ashesManageMain>

        <staEndUse ref="useMain" @refreshData="getData"></staEndUse>
	</div>


</template>
<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/common.scss";
.el-button + .el-button {
  margin-left: 0;
}
</style>
<script>
import ashesManageMain from "./ashesManageMain";
import staEndUse from "./staEndUse";
import dataTable from "@/components/Table/DataTable";
import apiBase from "@/api/apiBase.js";
import { formatDate, timeStringToDate } from "@/utils/date.js";
import { manage } from "@/mixins/managePage.js";
import { ORDER } from "@/const/orderConst.js";

const ADD = "新增";
const MODIFY = "修改";
const DELETE = "删除";
const INFO = "详情";

export default {
  name: "ashesManage",
  mixins: [manage],
  data() {
    return {
      selectData: {},
      ashesData: {},
      xMax: 100,
      yMax: 100,
      ashesTypes: [],
      areaTypes: []
    };
  },
  watch: {
    "ashesData.ASSASAID": function(val) {
      if (
        this.ashesData.ASSASAID !== null &&
        this.ashesData.ASSASAID !== undefined &&
        this.ashesData.ASSASAID !== ""
      ) {
        var data = {
          ASAID: this.ashesData.ASSASAID
        };
        apiBase.DoService(
          data,
          apiBase.getApiAdress().Ashesarea.Detail,
          res => {
            this.xMax = res.data.content.ASAXCOUNT;
            this.yMax = res.data.content.ASAYCOUNT;
          },
          res => {
            this.$message.error(res.data.msg);
          }
        );
      }
    }
  },
  methods: {
    //位置查询
    getData() {
      let data = {
        PageIndex: this.pageOrder.currentPage,
        PageSize: this.pageOrder.pageSize,
        OrderBy: this.pageOrder.orderType,
        OrderByType: this.pageOrder.orderSort,
        Data: JSON.parse(JSON.stringify(this.selectData))
      };
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Ashes.Query,
        res => {
          this.dataList = res.data.content.OutData;
          this.pageOrder.totalNum = res.data.content.RecordCount;
        },
        res => {
          this.$message.error(res.data.msg);
        }
      );
    },
    //获取位置类别
    getAssType() {
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Ashes.QueryAshesArea,
        res => {
          let assTypeData = res.data.content.OutData,
            legendsUsersData = assTypeData.map(item => ({
              label: item.ASANAME,
              value: item.ASAID
            }));
          this.areaTypes = legendsUsersData;
        },
        res => {
          this.$message.error(res.data.msg);
        }
      );
    },
    //获取表头
    getAssColumns() {
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Column.GetAshesColumns,
        res => {
          this.headList = res.data.content;
        },
        res => {
          this.$message.error(res.data.msg);
        }
      );
    },
    //功能操作
    operate(order) {
      this.order = order;
      this.dataRepeat();
      switch (this.order) {
        case ADD:
          this.$refs.sweetModalMain.open(this.order);
          break;
        case MODIFY:
        case INFO:
          this.$refs.sweetModalMain.open(this.order, this.currentRow.ASSID);
          break;
        case DELETE:
          this.$refs.sweetModalMain.open(this.order, this.currentRow.ASSID);
          break;
        case ORDER.START:
        case ORDER.END:
          this.$refs.useMain.open(this.order, this.currentRow.ASSID);
          break;
        default:
      }
    },
    //查询条件重置
    btnRepeat() {
      this.selectData = {};
      this.getData();
    },
    btnShow(btn) {
      let status = '';
      if (this.currentRow) {
        status = this.currentRow.ASSSTATUS;
      }
      switch (btn) {
        case ADD:
          return true;
          break;
        case INFO:
        case MODIFY:
        case DELETE:
          return status !== '';
          break;
        case ORDER.END:
          return status === 'A';
          break;
        case ORDER.START:
          return status === 'B';
        default:
      }
    },
    //数据重置
    dataRepeat() {
      this.ashesData = {};
    }
  },
  components: {
    ashesManageMain,
    staEndUse,
    dataTable
  },
  mounted() {},
  created() {
    this.getData();
    this.getAssType();
    this.getAssColumns();
  }
};
</script>